import 'package:f_demo/utils/index.dart';
import 'package:flutter/material.dart';
import 'package:f_demo/ui/pages/demo/index.dart';

class AnimationDemo extends StatefulWidget {
  @override
  _AnimationDemoState createState() => _AnimationDemoState();
}

class _AnimationDemoState extends State<AnimationDemo> with SingleTickerProviderStateMixin {
  Animation<double> _animation;
  AnimationController _animationController;

  @override
  void initState() {
    _animationController = AnimationController(duration: Duration(seconds: 3), vsync: this);

    _animation = CurvedAnimation(parent: _animationController, curve: Curves.bounceIn);

    _animation = Tween(begin: 0.0, end: 400.0).animate(_animation);
    start();
    super.initState();
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  void scale() {
    _animationController.reverse();
  }

  void start() {
    _animationController.forward();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Animation'),
      ),
      body: ListView(
        children: <Widget>[
          ListTile(
            title: Text('Scale'),
            trailing: Icon(Icons.navigate_next),
            onTap: () {
              Navigator.of(context).push(MaterialPageRoute(builder: (context) => ScaleAnimation()));
            },
          ),
          ListTile(
            title: Text('棋盘'),
            trailing: Icon(Icons.navigate_next),
            onTap: () {
              Navigator.of(context).push(MaterialPageRoute(builder: (context) => CustomPaintDemo()));
            },
          ),
          ListTile(
            title: Text('路由过渡动画'),
            trailing: Icon(Icons.navigate_next),
            onTap: () {
              Navigator.of(context).push(FadeRoute(page: NavigationAnimation()));
            },
          ),
          ListTile(
            title: Text('Hero过渡'),
            trailing: Icon(Icons.navigate_next),
            onTap: () {
              Navigator.of(context).push(FadeRoute(page: HeroDemo()));
            },
          ),
        ],
      ),
    );
  }
}
